let dispatcher = require('./dispatcher');

module.exports.chat = function (session, msg, app, cb) {
    let chatServers = app.getServersByType('chat');

    if (!chatServers || chatServers.length === 0) {
        cb(new Error('can not find chat servers.'));
        return;
    }

    let res = dispatcher.dispatch(session.get('rid'), chatServers);

    cb(null, res.id);
};

module.exports.psz = function (session, msg, app, cb) {
    let pszServers = app.getServersByType('psz');

    if (!pszServers || pszServers.length === 0) {
        cb(new Error('can not find chat servers.'));
        return;
    }

    console.log('-----pszServers.length---------', pszServers.length);
    let res = dispatcher.dispatch(session.get('room_id'), pszServers);

    cb(null, res.id);
};

module.exports.tenThirty = function (session, msg, app, cb) {
    let tenThirtyServers = app.getServersByType('tenThirty');

    if (!tenThirtyServers || tenThirtyServers.length === 0) {
        cb(new Error('can not find chat servers.'));
        return;
    }

    console.log('-----tenThirtyServers.length---------', tenThirtyServers.length);
    let res = dispatcher.dispatch(session.get('room_id'), tenThirtyServers);
    cb(null, res.id);
};